package com.lanou3g.musicenjoy.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou3g.musicenjoy.R;
import com.lanou3g.musicenjoy.entity.FlippableStackViewEntity;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.Bind;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by 李宁 on 15/10/27.
 * 滑动翻页适配器
 */
public class FlippableStackViewAdapter extends PagerAdapter {
    private List<FlippableStackViewEntity.DataEntity> data;
    private Context mContext;
    private TextView flippable_num,size,fli_sixpic_title,fli_sixpic_content,
            fli_pictop_title,fli_pictop_mid,fli_pictop_content,
            fli_bigpic_mid,fli_bigpic_content,
            fli_thrpic_title,fli_thrpic_content,
            fli_headpic_title,fli_headpic_mid,fli_headpic_content;
    private ImageView fli_sixpic_one,fli_sixpic_two,fli_sixpic_thr,fli_sixpic_four,fli_sixpic_five,fli_sixpic_six,
            fli_pictop_img,
            fli_bigpic_img,
            fli_thrpic_left,fli_thrpic_mid,fli_thrpic_right;
    private de.hdodenhof.circleimageview.CircleImageView fli_headpic_img;
    private View view;


    public FlippableStackViewAdapter(Context mContext, List<FlippableStackViewEntity.DataEntity> data) {
        this.mContext = mContext;
        this.data = data;
        Log.i("xiaowang", data + "data");

    }

    @Override
    public int getCount() {
        Log.i("xinixn", String.valueOf(data != null && data.size() > 0 ? data.size() : 0));
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        Log.i("xinixn", String.valueOf(view == object));
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        if (data.get(position).getAction().getType() == 13) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_fli_sixpic, null);
            fli_sixpic_one = (ImageView) view.findViewById(R.id.fli_sixpic_one);
            fli_sixpic_two = (ImageView) view.findViewById(R.id.fli_sixpic_two);
            fli_sixpic_thr = (ImageView) view.findViewById(R.id.fli_sixpic_thr);
            fli_sixpic_four = (ImageView) view.findViewById(R.id.fli_sixpic_four);
            fli_sixpic_five = (ImageView) view.findViewById(R.id.fli_sixpic_five);
            fli_sixpic_six = (ImageView) view.findViewById(R.id.fli_sixpic_six);
            flippable_num = (TextView) view.findViewById(R.id.flippable_num);
            fli_sixpic_title = (TextView) view.findViewById(R.id.fli_sixpic_title);
            fli_sixpic_content = (TextView) view.findViewById(R.id.fli_sixpic_content);
            size = (TextView) view.findViewById(R.id.size);

            Log.i("fjasfkja", data.get(position).getSmallPicUrls().get(0));
            Picasso.with(mContext).load(data.get(0).getSmallPicUrls().get(0)).into(fli_sixpic_one);
            Picasso.with(mContext).load(data.get(0).getSmallPicUrls().get(1)).into(fli_sixpic_two);
            Picasso.with(mContext).load(data.get(0).getSmallPicUrls().get(2)).into(fli_sixpic_thr);
            Picasso.with(mContext).load(data.get(0).getSmallPicUrls().get(3)).into(fli_sixpic_four);
            Picasso.with(mContext).load(data.get(0).getSmallPicUrls().get(4)).into(fli_sixpic_five);
            Picasso.with(mContext).load(data.get(0).getSmallPicUrls().get(5)).into(fli_sixpic_six);
            fli_sixpic_title.setText(data.get(0).getReason());
            fli_sixpic_content.setText(data.get(0).getName());
            flippable_num.setText(1 + "");
            size.setText(data.size() + "");
            container.addView(view);
        }
        if (data.get(position).getAction().getType() == 5) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_fli_pictop, null);
            fli_pictop_img = (ImageView) view.findViewById(R.id.fli_pictop_img);
            fli_pictop_title = (TextView) view.findViewById(R.id.fli_pictop_title);
            fli_pictop_mid = (TextView) view.findViewById(R.id.fli_pictop_mid);
            fli_pictop_content = (TextView) view.findViewById(R.id.fli_pictop_content);
            flippable_num = (TextView) view.findViewById(R.id.flippable_num);
            size = (TextView) view.findViewById(R.id.size);

            Picasso.with(mContext).load(data.get(position).getPicUrl()).into(fli_pictop_img);
            fli_pictop_title.setText(data.get(position).getReason());
            fli_pictop_mid.setText(data.get(position).getName());
            fli_pictop_content.setText(data.get(position).getDesc());
            flippable_num.setText(position + 1 + "");
            size.setText(data.size() + "");
            container.addView(view);
        }
        if (data.get(position).getAction().getType() == 21){
            view = LayoutInflater.from(mContext).inflate(R.layout.item_fli_bigpic,null);
            fli_bigpic_img = (ImageView) view.findViewById(R.id.fli_bigpic_img);
            fli_bigpic_mid = (TextView) view.findViewById(R.id.fli_bigpic_mid);
            fli_bigpic_content = (TextView) view.findViewById(R.id.fli_bigpic_content);
            flippable_num = (TextView) view.findViewById(R.id.flippable_num);
            size = (TextView) view.findViewById(R.id.size);

            Picasso.with(mContext).load(data.get(position).getPicUrl()).into(fli_bigpic_img);
            fli_bigpic_mid.setText(data.get(position).getName());
            fli_bigpic_content.setText(data.get(position).getDesc());
            flippable_num.setText(position + 1 + "");
            size.setText(data.size() + "");
            container.addView(view);
        }
        if (data.get(position).getAction().getType() == 22){
            view = LayoutInflater.from(mContext).inflate(R.layout.item_fli_thrpic, null);
            fli_thrpic_left = (ImageView) view.findViewById(R.id.fli_thrpic_left);
            fli_thrpic_mid = (ImageView) view.findViewById(R.id.fli_thrpic_mid);
            fli_thrpic_right = (ImageView) view.findViewById(R.id.fli_thrpic_right);
            fli_thrpic_title = (TextView) view.findViewById(R.id.fli_thrpic_title);
            fli_thrpic_content = (TextView) view.findViewById(R.id.fli_thrpic_content);
            flippable_num = (TextView) view.findViewById(R.id.flippable_num);
            size = (TextView) view.findViewById(R.id.size);

            Picasso.with(mContext).load(data.get(3).getSmallPicUrls().get(1)).into(fli_thrpic_left);
            Picasso.with(mContext).load(data.get(3).getSmallPicUrls().get(0)).into(fli_thrpic_mid);
            Picasso.with(mContext).load(data.get(3).getSmallPicUrls().get(2)).into(fli_thrpic_right);
            fli_thrpic_title.setText(data.get(3).getReason());
            fli_thrpic_content.setText(data.get(3).getName());
            flippable_num.setText(4 + "");
            size.setText(data.size() + "");
            container.addView(view);
        }
        if (data.get(position).getAction().getType() == 20){
            view = LayoutInflater.from(mContext).inflate(R.layout.item_fli_headpic,null);
            fli_headpic_img = (CircleImageView) view.findViewById(R.id.fli_headpic_img);
            fli_headpic_title = (TextView) view.findViewById(R.id.fli_headpic_title);
            fli_headpic_mid = (TextView) view.findViewById(R.id.fli_headpic_mid);
            fli_headpic_content = (TextView) view.findViewById(R.id.fli_headpic_content);
            flippable_num = (TextView) view.findViewById(R.id.flippable_num);
            size = (TextView) view.findViewById(R.id.size);

            Picasso.with(mContext).load(data.get(position).getPicUrl()).into(fli_headpic_img);
            fli_headpic_title.setText(data.get(position).getReason());
            fli_headpic_mid.setText(data.get(position).getName());
            fli_headpic_content.setText(data.get(position).getDesc());
            flippable_num.setText(position + 1 + "");
            size.setText(data.size() + "");
            container.addView(view);
        }


        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
